﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using ModelLayer;
using AssessmentTool.Services.DTO;
using System.Linq;
using AssessmentTool.ServiceBridge;
using AssessmentTool.PresentationLogic.EventArguments;

namespace AssessmentTool.PresentationLogic
{
    
    public class CompetenzaBuilder
    {
        public readonly static int LEVEL_DOMANDE = 3;
        public static CompetenzaBuilder _instance;
       
        
        public static CompetenzaBuilder getInstance()
        {
            if (_instance == null)
                _instance = new CompetenzaBuilder();
            return _instance;
        }
        private CompetenzaBuilder()
        { 
        }


        public void generateCompetezaTree(IContainer padre, ModelLayer.Modello m)
        {
            IEnumerable<ModelLayer.Competenza> competenze = m.Competenze.Where(x => x.Livello == 1);
            foreach (ModelLayer.Competenza competenza in competenze)
            {
                CompetenzaContainer container = new CompetenzaContainer();
                generateCompentenzaTreeRecursive(padre, competenza);

            }
        }


        public void generateCompentenzaTreeRecursive(IContainer padre,ModelLayer.Competenza competenza)
        {
            if (competenza.Livello!=LEVEL_DOMANDE)
            {
                CompetenzaContainer container = new CompetenzaContainer();
                
                container.setIContainerParent(padre);
                container.initWithCompetenza(competenza);
                
                foreach (ModelLayer.Competenza figlio in competenza.Figli)
                {
                    generateCompentenzaTreeRecursive(container, figlio);
                }
                padre.addChild(container);
                
            }
            else 
            {
                
                Competenza domanda = new Competenza();
                domanda.setIContainerParent(padre);
                domanda.initWithCompetenza(competenza);
                padre.addChild(domanda);
                
            }
            return;

        }

        
    }
}
